define(function(require, exports, module){
	require("resource/js/easyui/easyloader.js");
	require("resource/js/easyui/themes/icon.css");
	require.async("resource/js/component/rules.js");
	var ajax = require("resource/js/component/ajax.js");
	var EC = require("resource/js/component/easycombobox.js");
	var Obj = window.loadI18n('base/user');
	EC.create({
		url:BASEPATH+"/base/authoriza/basecode/getType.htm",
		param:{checkeds:"sex"}
	});
	$("#modifyCode").click(function(){
		$(".modifyPassword").show().siblings().hide();
	});
	$("#modifyperInfo").click(function(){
		$(".modifyPerInfo").show().siblings().hide();
	});
	$(".rtn-back").click(function(){
		$("#ListInfo").show().siblings().hide();
	})

	var initForm = function(){
		$("#userImg").upload({
			title:""+Obj.get('base.common.success.Headchoose')+"",
			cropper:true,
			param:{exts:"png,jpg,bmp,jif"},
			onSuccessAfter:function(files){
				var url = files[0].preview||files[0].fileUrl;
				$("#userImg").val(url);
//				$("#userIcon").attr("src",BASEPATH+url);
			}
		});
		/*$("#userIcon").click(function(){
			$("#userImg").upload("show");
		});*/
		
		getInfo();
		$("#btn-save").bind("click",function(){
			using(["form"],function(){
				if($("#userupdpassword").form("validate")){
					//$("#userupd").form("submit");
					//取得form数据
					var req_data = $("#userupdpassword").serializeJson();
					
					//加载加密js
					var MD5 = require("resource/js/component/md5.js");
					//对新密码加密
					var password = MD5.md5($("#password").val()).toUpperCase();
					//对原密码加密
					var oldPassword = MD5.md5($("#oldPassword").val()).toUpperCase();
					req_data.password = password;
					req_data.oldPassword = oldPassword;
					req_data.phone = $("#mobile").val();
					//提交数据
					ajax.init().success(function(code,msg,data){
						using(['messager'],function(){
							$.messager.alert(""+Obj.get('base.common.success.Systemprompt')+"",msg,'',function(){
//								indexApp.exec("logout");
//								window.location.href=''+BASEPATH+'/view/base/main/login'  ;
							});
						});
					}).error(function(code,msg,data){
						if(msg!=""){
							using(['messager'],function(){
								$.messager.alert(""+Obj.get('base.common.success.Systemprompt')+"",msg);
							});
						}
					}).post(BASEPATH+"/base/authoriza/user/updPsd.htm",req_data);
				}
			});
		});
		
		//提交
		$("#btn-save-info").bind("click",function(){
			using(["form"],function(){
				if($("#userupdInfo").form("validate")){
					var req_data = $("#userupdInfo").serializeJson();
					ajax.init().success(function(code,msg,data){
						getInfo();
						if(msg!=""){
							$.messager.show({
								title:'',
								msg:msg,
								timeout:5000,
								showType:'slide'
							});
						}
					}).error(function(code,msg,data){
						if(msg!="")
							$.messager.alert(""+Obj.get('base.common.success.Systemprompt')+"",msg);
						getInfo();
					}).contentType("application/json").post(BASEPATH+"/base/authoriza/user/update.htm",JSON.stringify(req_data));
				}
			});
		});
	}
	
	
	var getInfo = function(){
		if(indexApp)
			indexApp.exec("initUser",function(data){
				$("#getuserName").html(data.userName);
				$("#getmobile").html(data.mobile);
				$("#getuseremail").html(data.email);
				EC.init({ele:"#sex",groupType:"sex",emptyval:false});
		
				$("#userupdpassword").form("load",data);
				$("#userupdInfo").form("load",data);
				if(data.userImg){
//					$(".userIcon").attr("src",BASEPATH+data.userImg);
//					$("#userIcon").attr("src",BASEPATH+data.userImg);
				}
			});
	}
	
	exports.init=function(){
		using(["textbox","form","combobox","upload","parser","corp"],function(){
			initForm();
		});
	}	
});



















